<template>
  <div class="subject">
    <span>{{ num1 }}</span>
    <span>+</span>
    <span>{{ num2 }}</span>
    <span>=</span>
    <input type="number" v-model.number="userAnswer" />
    <button @click="handleCalc">提交</button>
  </div>
</template>

<script>
export default {
  props: {
    num1: Number,
    num2: Number
  },
  data() {
    return {
      userAnswer: ""
    };
  },
  methods: {
    handleCalc() {
      if (!this.userAnswer) return;
      this.$emit("update:showResult", true);
      if (this.userAnswer === this.num1 + this.num2) {
        this.$emit("update:answer", true);
      } else {
        this.$emit("update:answer", false);
      }
    }
  }
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>